using System.Collections.Generic;
using Gameplay.PVE.Config;
using Gameplay.PVE.Data;
using Gameplay.PVE.Entity;
using UnityEngine;

namespace Gameplay.PVE.Skill
{
    public class DynamicObstacle : SkillBullet
    {
        private Vector3 position;
        private Vector3 forward;
        
        public void SetTargetPositionAndForward(Vector3 position, Vector3 forward)
        {
            this.position = position - PveManager.Instance.startPosition;
            this.forward = forward;
        }
        
        public override void Initialize(PveSkillBulletConfig config, PveSkillConfig skillConfig,SkillBase skill, Vector3 startPosition, Vector3 offset, Vector3 angle,
            UnitBase source)
        {
            base.Initialize(config, skillConfig,skill, startPosition, offset, angle, source);
            float id;
            float hp;
            float width;
            float height;
            float breakId;
            config.param.TryGetValue("obstacleId", out id);
            config.param.TryGetValue("hp", out hp);
            config.param.TryGetValue("width", out width);
            config.param.TryGetValue("height", out height);
            config.param.TryGetValue("breakId", out breakId);

            var obstacle = new RpgLevelData.RpgObstacle
            {
                obstacleId = (int) id,
                playerHidePoints = new List<Vector3>(),
                enemyHidePoints = new List<Vector3>(),
                breakId = (int) breakId,
                height = (int) height,
                width = (int) width,
                hp = (int) hp,
                position = this.position,
                rotation = Quaternion.FromToRotation(Vector3.zero,forward).eulerAngles,
                scale = new Vector3(1, 1, 1),
            };
            UnitManager.Instance.AddObstacle(PveManager.Instance.stageId,obstacle,PveManager.Instance.startPosition);
        }
    }
}